package com.batch.step;

import com.batch.listener.StepListener1;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class GeneralStep {

    // Step构建工厂，用于构建 Step 对象
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ApplicationContext context;

    @Bean
    public Step step01() {
        return stepBuilderFactory.get("step01").tasklet((Tasklet) context.getBean("tasklet01"))
                .build();
    }

    @Bean
    public Step step02() {
        return stepBuilderFactory.get("step01").tasklet((Tasklet) context.getBean("tasklet02"))
                .build();
    }

    @Bean
    public Step step03() {
        return stepBuilderFactory.get("step01").tasklet((Tasklet) context.getBean("tasklet03"))
                .listener(new StepListener1())
                .build();
    }
}
